#include "StdAfx.h"
#include "PointLight.h"


CPointLight::CPointLight(void)
{
}


CPointLight::~CPointLight(void)
{
}

CColor4 CPointLight::Shade(const CRay& vRay, const CVector3D& vPoint, const CVector3D& vNormal, const CGeometry& geometry, DATA_TYPE fTransparency) const
{
	CColor4 ambient = geometry.GetColor() * m_vColor * m_fAmbient;
	if (fTransparency < EPSILON)
	{
		return ambient;
	}

	CVector3D l = (GetPosition() - vPoint).Normalize();
	
	CVector3D vTemp = (l - vRay.GetDir());
	CVector3D h = vTemp / vTemp.GetLength();

	CColor4 diffuse = geometry.GetColor() * m_vColor * __max(0, vNormal.Dot(l));
	CColor4 specular = m_vColor * __max(0, powf(vNormal.Dot(h), geometry.GetMaterial().phongExponent));

	return ambient + fTransparency * (diffuse + specular);
}